//
//  SQQueryViewController.m
//  energy
//
//  Created by 周曼迪 on 2021/7/8.
//

#import "SQQueryViewController.h"

#import "SQQueryModel.h"
#import "SQHierarchyModel.h"

#import "SQPlayVoiceView.h"
#import "SQShowImage.h"

@interface SQQueryViewController ()<BaseTableVCInterface>
@property (weak, nonatomic) IBOutlet UITextField *tf_area;//区域
@property (weak, nonatomic) IBOutlet UITextField *tf_hierarchy;//层级
@property (weak, nonatomic) IBOutlet UITextField *tf_people;//责任人
@property (weak, nonatomic) IBOutlet UITextView *tv_content;

@property (weak, nonatomic) IBOutlet UIImageView *img_picOne;
@property (weak, nonatomic) IBOutlet UIImageView *img_picTwo;
@property (weak, nonatomic) IBOutlet UIImageView *img_picThree;

@property (strong, nonatomic) SQQueryModel * queryModel;

@property (weak, nonatomic) IBOutlet UIView *view_voice;
@property (strong, nonatomic) SQPlayVoiceView * playVoiceView;

@end

@implementation SQQueryViewController

- (void)viewDidLoad {
    self.tableViewInterface = self;
    [super viewDidLoad];
    self.navigationItem.title = @"隐患详情";
    
    self.playVoiceView = [[SQPlayVoiceView alloc] init];
    [self.view_voice addSubview:self.playVoiceView];
    
    [self getQueryData];

}

-(void)getQueryData{
    [SQQueryModel getDataWithParams:@{@"hd_id":self.hd_id} WithCallBack:^(SQQueryModel * data) {
        self.queryModel = data;
        [self getHierarchy];
        self.tf_area.text = data.data.site_area;
        self.tv_content.text = data.data.hd_danger_description;
        
        [self.img_picOne setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",LC_ReqHeader,data.data.hd_report_pic_one]] placeholder:[UIImage imageNamed:@"addImage"]];
        
        [self.img_picTwo setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",LC_ReqHeader,data.data.hd_report_pic_two]] placeholder:[UIImage imageNamed:@"addImage"]];
        
        [self.img_picThree setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",LC_ReqHeader,data.data.hd_report_pic_three]] placeholder:[UIImage imageNamed:@"addImage"]];
        
        [self.playVoiceView buildPlayVoiceVie:data.data.hd_report_pic_audio];
       
    }];
}

-(void)getHierarchy{
    NSString * os_level;
        if ([MLevel isEqualToString:@"1"] ) {
            os_level = MOne;
        }else if ( [MLevel isEqualToString:@"2"] || [MLevel isEqualToString:@"3"]){
            os_level = MTwo;
        }else if ( [MLevel isEqualToString:@"4"] ){
            os_level = MThree;
        }
    
    
    [SQHierarchyModel getDataWithParams:@{@"m_enterprise_id":MEnterpriseId,@"m_level":MLevel,@"os_level":os_level} WithCallBack:^(SQHierarchyModel * data) {
        for (int i = 0; i < data.data.count; i ++) {
            SQHierarchyModelArray * dataModel = data.data[i];
            if ([self.queryModel.data.hd_confirm_department_id isEqualToString:dataModel.os_id]) {
                self.tf_hierarchy.text = dataModel.os_name;
                for (int f = 0; f < dataModel.personnel.count; f ++) {
                    SQHierarchyModelPersonnelArray * personnelModel = dataModel.personnel[f];
                    if ([personnelModel.m_id isEqualToString:self.queryModel.data.hd_confirm_person_id]) {
                        self.tf_people.text = personnelModel.m_name;
                    }
                }
                
            }
            
        }
        
        
        

    }];
}


-(NSInteger)rowsCount:(NSInteger)section{
    return 0;
}


-(NSArray<NSArray<NSString *> *> *)classArr{
    return @[@[@"SQHiddenDangerTableViewCell"]];
}
#pragma mark -- 图片放大
- (IBAction)clickShowImage:(UIButton *)sender {

    if (sender.tag == 10) {
        if ([self haveStr:@[self.queryModel.data.hd_report_pic_one]]) {
            [SQShowImage showImage:self.img_picOne];
            
        }
        
    }else if (sender.tag == 20){
        if ([self haveStr:@[self.queryModel.data.hd_report_pic_two]]) {
            [SQShowImage showImage:self.img_picTwo];
        }
        
        
    }else if (sender.tag == 30){
        if ([self haveStr:@[self.queryModel.data.hd_report_pic_three]]) {
            [SQShowImage showImage:self.img_picThree];
        }
            
    }
}


- (BOOL)haveStr:(NSArray<NSString *> *)strs{
    for (NSString *key in strs) {
        if (key.length > 0) {
            return YES;
        }
    }
    return NO;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
